import os
from pyquery import PyQuery as pq
def writeToText(path,dest):
 fo = open(dest, "w+")
 for fpathe,dirs,fs in os.walk(path):
  for f in fs:
    html = os.path.join(fpathe,f)
    d=pq(filename=html,encoding="gbk")
    table=d('table').eq(4)
    for i in range(2,10):
       tr=table('tr').eq(i)
       line=tr('td').eq(0).text()+"\t"+tr('td').eq(1).text()+"\t"+tr('td').eq(2).text()+"\t"+tr('td').eq(10).text()+"\n"
       line=line.encode('utf-8')
       if line.isspace():
           continue
       fo.write(line)
 fo.close()

if __name__ == "__main__":
 writeToText(r"D:\consume",r"D:\1.txt")